#include <Windows.h>
#include <time.h>
#include <conio.h>
#include <stdio.h>
#include "game.h"

int main (int argc, char ** argv)
{
	//remove console cursor
	CONSOLE_CURSOR_INFO cursor_data;
	cursor_data.bVisible = false;
	cursor_data.dwSize = 1;
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_data);

	//Initialize
	Game g;
	srand((unsigned int) time(NULL));
	time_t timer, then = clock(), now, passed;
	int input;
	//Game Loop
 	while(g.isRunning())
	{
		//Input
		if(_kbhit())
		{
 			input = _getch();
			if(input == 'q') return 1;
			g.handleInput(input);
		}
		else
		{
			//calculate the passage of time
			now = clock();
			passed = now - then;
			then = now;
			//Logic/update
			g.update((int)passed);
			//draw
			g.draw();
			//Throttle code
			timer = clock() + 200;
			while(!_kbhit() && clock() < timer){Sleep(1);}
		}
	}
}